<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.gxgyl.com All rights reserved.

// +----------------------------------------------------------------------
// | Author: Liuyu
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\controller;

use app\api\model\Article as ArticleModel;
use app\api\service\User as UserService;

/**
 * 文章控制器
 * Class Article
 * @package app\api\controller
 */
class Article extends Controller {
	/**
	 * 文章列表
	 * @param int $categoryId
	 * @return \think\response\Json
	 * @throws \think\db\exception\DbException
	 */
	public function list(int $categoryId = 0) {
		$model = new ArticleModel;
		$list = $model->getList($categoryId);
		return $this->renderSuccess(compact('list'));
	}

	/**
	 * 文章详情
	 * @param int $articleId
	 * @return \think\response\Json
	 * @throws \cores\exception\BaseException
	 */
	public function detail(int $articleId) {
		$detail = ArticleModel::getDetail($articleId);
		return $this->renderSuccess(compact('detail'));
	}
	public function detail_user() {
		// 当前用户信息
		$userInfo = UserService::getCurrentLoginUser(true);
		switch ($userInfo['grade_id']) {
		case 1:
			$articleId = 1;
			break;
		case 2:
			$articleId = 2;
			break;
		case 3:
			$articleId = 3;
			break;

		default:
			$articleId = 4;
			break;
		}
		$detail = ArticleModel::getDetail($articleId);
		return $this->renderSuccess(compact('detail'));
	}
}
